8.1 - Introduction to Harmony
Harmony patching allows you to add onto or replace existing methods in the game.
This can be used to change certain behaviors of the game, run your code at specific points or completely prevent certain methods from running.
There are 4 types of Harmony patches:
- Prefix
- Postfix
- Transpiler
- Finalizer
Prefix
A prefix patch is a patch that runs before the original method.
Postfix
A postfix patch is a patch that runs after the original method.
Transpiler
A transpiler patch is a patch that allows you to modify the original method's IL code.
Due to Sons of the Forest using IL2CPP this patch type should generally be avoided.
Finalizer
A finalizer patch is a patch that runs after the original method and can be used to handle any exceptions that may occur in the original method.
This can be used for different purposes, but the primary use case is to catch any errors that may occur in the original method.
The finalizer always runs after any postfix patches, even if the postfix or original method throws an exception.
It is important to note that this guide only goes over the basics of harmony patching, for a more in depth explanation on what harmony is capable of you can check the official Harmony documentation here.